home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 265_01 / biowrsct.c < prev    next >
Text File  |  1990-02-13  |  2KB  |  51 lines

  1. /* vi: set ai : */
  2. /* IBM PC BIOS version    written by Rainer Gerhards */
  3. /* CURRENTLY MSC NEEDED!!!! */
  4. /* Only the IBM 360Kb format is supported. There have to be 2 sides, */
  5. /* each side has to have 40 tracks and each track 9 sectors of 512 bytes. */
  6. /* Any other physical format will cause the program to fail. */
  7. #include <stdio.h>
  8. #include <dos.h>
  9.  
  10. #define    RETRIES    3
  11.  
  12. int        wrsct(strtsect, sectbuf)
  13. int        strtsect;
  14. char        *sectbuf;
  15. {
  16. int        error = 1;
  17. int        tries;
  18. int        diskstat;
  19. char far    *bufadr = (char far *) sectbuf;
  20. union REGS    regs;
  21. struct SREGS    sregs;
  22.  
  23. bufadr = (char far *) sectbuf;
  24. for(tries = RETRIES ; tries > 0 ; --tries)    
  25.     {
  26.     regs.h.ah = 3;            /* write sector    */
  27.     regs.h.al = 1;            /* one sector    */
  28.     regs.h.dl = 0;            /* drive one    */
  29.     regs.h.cl = (strtsect % 9) + 1;    /* sector    */
  30.     regs.h.ch = (strtsect / 2) / 9;    /* track    */
  31.     regs.h.dh = (((strtsect % 18) / 9) > 0) ? 1 : 0;/* side        */
  32.     regs.x.bx = FP_OFF(bufadr);    /* data buffer    */
  33.     sregs.es = FP_SEG(bufadr);    /* data buffer    */
  34.     int86x(0x13, ®s, ®s, &sregs);        /* call bios    */
  35.     if(regs.x.cflag)        /* error?    */
  36.         {
  37.         diskstat = regs.h.ah;    /* save error    */
  38.         regs.h.ah = 0;        /* reinitialize    */
  39.         int86x(0x13, ®s, ®s, &sregs);    /* do it!    */
  40.         }
  41.     else
  42.         {
  43.         tries = 0;        /* end loop    */
  44.         error = 0;        /* "good" state    */
  45.         }
  46.     }
  47. if(error == 1)
  48.     fprintf(stderr, "ERROR: disk status 0x%2.2x\n", diskstat);
  49. return(error);
  50. }
  51.